package com.krazevina.kar;

import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.List;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.layouts.FlowLayout;
import com.sun.lwuit.plaf.Style;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;

public final class MainForm extends Form{
    TextArea txtSearch;
    Button btnsearch,btnlang;
    Label more;Container searchbox;
    List lv;Container abc;
    Button bttim,btabc,btcode,btfav;
    boolean abcshow = false;
    final int SIZEPERPAGE=20;
    
    InputStream inps;
    Vector vout;
    Vector cout;
    InputStreamReader ir;
    BufferedReader in;
    Image fav,nofav;
    Dialog menu;
    Label lblAbc;
    static boolean headerSearch = false;
    
    public MainForm() {
        try {
            getStyle().setBgImage(FirstForm.backgr);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        getStyle().setBgTransparency(255);
        lv = new List();
        lv.setRenderer(new ListCellRender());
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        HeaderMain();
        addCmd();
        pageMark = new int[1000];
        searching = new Label("Đang tìm...");
        result = new Vector();
        resultArt = new Vector();
        new parsenew().start();
    }

    public void show() {
        if(searchType==5)lastSearch="";
        super.show();
        page = 0;newLv();
        if(!headerSearch){
            if(searchType!=4)search();
            else findFav();
        }
        else HeaderSearch();
    }
    
    Vector result;
    Vector resultArt;
    int page = 0;Label searching;
    boolean next;
    
    void search(){
        searching = new Label("Đang tìm...");
        result = new Vector();
        newLv();
        searching.setText("Đang tìm...");
        lv.addItem(searching);
        repaint();
        System.out.println("search:"+lastSearch);
        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(100);
                    if(searchType<=4&&searchType>0){//Search all, fav...
                        if(searchThread!=null&&searchThread.isAlive())searchThread.interrupt();
                        searchThread = new findAll(""+lastSearch,page);
                        searchThread.start();
                    }else if(searchType==0){//Search abc
                        if(searchThreadABC!=null&&searchThreadABC.isAlive())searchThreadABC.interrupt();
                        searchThreadABC = new findABC(""+lastSearch,page);
                        searchThreadABC.start();
                    }else{//Artist = 5
                        System.out.println("search thr:"+lastSearch);
                        if(searchThreadArt!=null&&searchThreadArt.isAlive())searchThreadArt.interrupt();
                        searchThreadArt = new findAllArtists(lastSearch,page);
                        searchThreadArt.start();
                    }
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }).start();
    }
    
    void newLv(){
        try{
            if(lblAbc!=null&&contains(lblAbc))
                removeComponent(lblAbc);
            if(lv!=null&&contains(lv))removeComponent(lv);
            lv = new List();
            lv.setRenderer(new ListCellRender());
            lv.setPreferredH(getHeight()-90);
            addComponent(lv);
            lv.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    if(searchType<5&&lv.getSelectedIndex()==result.size()&&next){
                        page++;result.removeAllElements();
                        resultArt.removeAllElements();
                        more.setText("Đang tìm...");
                        repaint();
                        search();
                    }else if(searchType==5&&lv.getSelectedIndex()==resultArt.size()&&next){
                        page++;result.removeAllElements();
                        resultArt.removeAllElements();
                        more.setText("Đang tìm...");
                        repaint();
                        search();
                    }else{
                        if(searchType==0&&lv.getSelectedIndex()==0)return;
                        if(searchType==5){
                            lastSearch = ((Artist)resultArt.elementAt(lv.getSelectedIndex())).name;
                            page = 0;
                            searchType = 1;
                            search();
                        }
                        else{
                            Song s = (Song)result.elementAt(lv.getSelectedIndex());
                            if(!s.isFav()){
                                s.fav();
                                ((Label)vout.elementAt(lv.getSelectedIndex())).setIcon(fav);
                            }
                            else{
                                s.unFav();
                                ((Label)vout.elementAt(lv.getSelectedIndex())).setIcon(null);
                            }
                        }
                        repaint();
                    }
                }
            });
        }catch(Exception e){e.printStackTrace();}
    }
    
    int[]pageMark;
    public static String lastSearch="";
    /**
     * searchType = 0 : search by ABC<br/>
     * = 1 : search song by artist<br/>
     * = 2 : search by code<br/>
     * = 3 : search by all<br/>
     * = 4 : search fav<br/>
     * = 5 : search artist
     */
    public static int searchType;
    
    void HeaderSearch(){
        if(searchbox!=null&&contains(searchbox)){
            removeComponent(searchbox);
        }
        searchbox = new Container(new BoxLayout(BoxLayout.X_AXIS));
        searchbox.setPreferredH(45);
        txtSearch = new TextArea();
        if(searchType!=5)txtSearch.setHint("Tên, lời bài hát");
        else txtSearch.setHint("Ca sĩ, nhạc sĩ");
        txtSearch.setPreferredW((int)(getWidth()*0.55f));
        btnlang = new Button("Back");
        try {
            Image i = Image.createImage("/btnsearch.png");
            btnsearch = new Button(i);
        } catch (IOException ex) {
            btnsearch = new Button("Tìm");
        }
        try {
            Image i;
            i = Image.createImage("/back.png");
            searchbox.getStyle().setBgImage(i);
            searchbox.getStyle().setBgTransparency(255);
        } catch (IOException ex) {
        }
        S.sets(txtSearch);
        S.setBtnSearchStyle(btnsearch);
        S.setBtnLangStyle(btnlang);
        searchbox.addComponent(btnsearch);
        searchbox.addComponent(txtSearch);
        searchbox.addComponent(btnlang);
        addComponent(0,searchbox);
        setFocused(txtSearch);
        btnsearch.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                lastSearch = txtSearch.getText();
                if(txtSearch.getText().length()>1){
                    lastSearch = txtSearch.getText().toString();
                    if(searchType!=5)searchType = 2;page = 0;
                    search();
                }
            }
        });
        btnlang.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                HeaderMain();
                repaint();
            }
        });
        repaint();
    }
    
    void HeaderMain(){
        try{
            if(searchbox!=null&&contains(searchbox)){
                removeComponent(searchbox);
            }
            Image top1,top2,top3,top4;
            try {
                top1 = Image.createImage("/top1.png");
                top2 = Image.createImage("/top2.png");
                top3 = Image.createImage("/top3.png");
                top4 = Image.createImage("/top4.png");
                fav = Image.createImage("/fav.png");
                searchbox = new Container(new BoxLayout(BoxLayout.X_AXIS));
                bttim = new Button(top1);
                btabc = new Button(top2);
                btcode = new Button(top3);
                btfav = new Button(top4);
                S.setTransTop(bttim, getWidth()/4);
                S.setTransTop(btabc, getWidth()/4);
                S.setTransTop(btcode, getWidth()/4);
                S.setTransTop(btfav, getWidth()/4);
                searchbox.addComponent(bttim);
                searchbox.addComponent(btabc);
                searchbox.addComponent(btcode);
                searchbox.addComponent(btfav);
                bttim.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        HeaderSearch();
                    }
                });
                btabc.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if(!abcshow){
                            showABC();
                            abcshow = true;
                            repaint();
                        }
                    }
                });
                btcode.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        searchType = 2;page = 0;
                        abcshow = false;
                        lastSearch = "";
                        search();
                    }
                });
                btfav.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        abcshow = false;
                        findFav();
                    }
                });
                addComponent(0,searchbox);
                repaint();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    String label;
    void showABC(){
        if(abc==null){
            abc = new Container(new FlowLayout());
            abc.getStyle().setAlignment(Container.CENTER);
            Button b;
            Button num = new Button("0-9");
            S.setTransABC(num, getWidth()/4-6);
            num.addActionListener(new ActionListener() {
                    String s = ""+label;
                    public void actionPerformed(ActionEvent ae) {
                        abcshow = false;
                        removeComponent(abc);
                        searchType = 0;page = 0;
                        lastSearch = "0";
                        search();
                    }
                });
            abc.addComponent(num);
            for(int i=0;i<26;i++){
                label = new String(new byte[] {(byte)(i+65)});
                b = new Button(label);
                S.setTransABC(b, getWidth()/4-6);
                b.addActionListener(new ActionListener() {
                    String s = ""+label;
                    public void actionPerformed(ActionEvent ae) {
                        abcshow = false;
                        removeComponent(abc);
                        searchType = 0;page = 0;
                        lastSearch = s.toLowerCase();
                        search();
                    }
                });
                abc.addComponent(b);
            }
        }
        if(lv!=null&&contains(lv))removeComponent(lv);
        addComponent(1,abc);
    }
    
    
    void showResult(){
        newLv();
        Label name; Label lyric,ID,artist;
        Label lblfav;
        Container out,child,outer,linehold;
        Song item;Artist art;
        vout = new Vector();
        if(searchType==5){
            for(int i=0;i<resultArt.size();i++){
                art = (Artist) resultArt.elementAt(i);
                name = new Label(art.name);
                name.setPreferredW(getWidth());
                name.setPreferredH(40);
                S.setTrans(name);
                Container line = new Container();
                line.setPreferredH(1);
                line.setPreferredW(getWidth());
                line.getStyle().setBgColor(0x333333);
                line.getStyle().setBgTransparency(255);
                linehold = new Container(new BoxLayout(BoxLayout.Y_AXIS));
                linehold.addComponent(name);
                linehold.addComponent(line);
                linehold.setLeadComponent(name);
                lv.addItem(linehold);
            }
        }else{
            if(searchType==0){
                if(lastSearch.equals("0"))lblAbc = new Label("0-9");
                if(lblAbc!=null&&contains(lblAbc))removeComponent(lblAbc);
                lblAbc = new Label(""+lastSearch.toUpperCase());
                S.setTransLblAbc(lblAbc);
                lblAbc.setPreferredH(25);
                addComponent(1,lblAbc);
            }
            for(int i=0;i<result.size();i++){
                item = (Song) result.elementAt(i);
                out = new Container(new BoxLayout(BoxLayout.Y_AXIS));
                child = new Container(new BoxLayout(BoxLayout.X_AXIS));
                outer = new Container(new BoxLayout(BoxLayout.X_AXIS));

                name = new Label(item.name);
                lyric = new Label(item.lyric+"  -");
                ID = new Label(""+item.ID);
                artist = new Label(item.artist+"  -");

                if(item.isFav())lblfav = new Label(fav);
                else lblfav = new Label("");

                S.setTrans1(lyric,0x000000);
                S.setTrans1(artist,0x000000);
                S.setTrans1(ID,0x05b3e8);
                S.setTrans(name);
                S.setTrans(lblfav);
                artist.setPreferredW(getWidth()-120);

                child.addComponent(artist);
                child.addComponent(ID);

                out.addComponent(name);
                out.addComponent(child);
                out.addComponent(lyric);

                out.getStyle().setBgTransparency(0);
                outer.getStyle().setBgTransparency(0);

                outer.addComponent(lblfav);
                outer.addComponent(out);
                Container line = new Container();
                line.setPreferredH(1);
                line.setPreferredW(getWidth());
                line.getStyle().setBgColor(0x333333);
                line.getStyle().setBgTransparency(255);
                linehold = new Container(new BoxLayout(BoxLayout.Y_AXIS));
                linehold.addComponent(outer);
                linehold.addComponent(line);
                linehold.setLeadComponent(name);
                vout.addElement(lblfav);
                lv.addItem(linehold);
            }
        }
        lv.setItemGap(2);
        if(searchType!=5){
            if(result.size()%SIZEPERPAGE==0&&result.size()>0){
                more = new Label("Tiếp");
                lv.addItem(more);
            }
        }else{
            if(resultArt.size()%SIZEPERPAGE==0&&resultArt.size()>0){
                more = new Label("Tiếp");
                lv.addItem(more);
            }
        }
        repaint();
    }
    
    findAll searchThread;
    findABC searchThreadABC;
    findAllArtists searchThreadArt;
    
    class findAll extends Thread{
        String searchterm;
        int page;
        public findAll(final String re, final int page){
            searchterm = re.toLowerCase();this.page = page;
            if(page==0)for(int i=0;i<pageMark.length;i++)pageMark[i] = 0;
        }
        public void run(){
            next = false;
            System.out.println("Search:"+searchterm);
            searchterm = searchterm.toLowerCase().trim();
            inps = getClass().getResourceAsStream("/song.txt");
            int j;
            try{
                ir = new InputStreamReader(inps,"UTF-8");
                in = new BufferedReader(ir);
                String s1="";
                Song song;
                int i1;
                System.out.println("from "+pageMark[page]+" / type = "+searchType);
                for(i1=0;i1<pageMark[page];i1++)
                    in.readLine();
                
                outside:for(i1=pageMark[page];i1<13854;i1++){
                    s1 = in.readLine();
                    if(searchType==4){
                        for(j=0;j<favlist.length;j++)
                        if(s1.startsWith(""+favlist[j])){
                            song = new Song(s1);
                            result.addElement(song);
                            if(result.size()>=(1)*SIZEPERPAGE){
                                pageMark[page+1] = i1;
                                next = true;
                                break outside;
                            }
                            if(result.size()>=favlist.length){
                                pageMark[page+1] = i1;
                                next = false;
                                break outside;
                            }
                            break;
                        }
                    }else if(s1.toLowerCase().indexOf(searchterm)>=0){
                        song = new Song(s1);
//                        song.out();
                        if(searchType!=1&&song.isName(searchterm)<10){
                            result.addElement(song);
                            if(result.size()>=(1)*SIZEPERPAGE){
                                pageMark[page+1] = i1;
                                next = true;
                                break;
                            }
                        }else if(searchType==2){
                            result.addElement(song);
                            if(result.size()>=(1)*SIZEPERPAGE){
                                pageMark[page+1] = i1;
                                next = true;
                                break;
                            }
                        }else if(searchType!=1&&song.isLyrics(searchterm)<10){
                            result.addElement(song);
                            if(result.size()>=(1)*SIZEPERPAGE){
                                pageMark[page+1] = i1;
                                next = true;
                                break;
                            }
                        }else if(searchType==1&&song.isArtist(searchterm)<10){
                            result.addElement(song);
                            if(result.size()>=(1)*SIZEPERPAGE){
                                pageMark[page+1] = i1;
                                next = true;
                                break;
                            }
                        }
                    }
                    if(i1%3000==0)System.out.println(""+i1);
                }
                inps.close();
                in.close();
                if(result.size()<=0){
                    searching.setText("Không có kết quả.");
                    repaint();
                }
                else showResult();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    
    class findABC extends Thread{
        String searchterm;
        int page;
        public findABC(final String re, final int page){
            searchterm = re.toLowerCase();this.page = page;
            if(page==0)for(int i=0;i<pageMark.length;i++)pageMark[i] = 0;
        }
        public void run(){
            next = false;
            System.out.println("Search ABC:"+searchterm);
            searchterm = searchterm.toLowerCase().trim();
            inps = getClass().getResourceAsStream("/song.txt");
            try{
                ir = new InputStreamReader(inps,"UTF-8");
                in = new BufferedReader(ir);
                String s1="";
                Song song;
                int i1;
                System.out.println("from "+pageMark[page]);
                for(i1=0;i1<pageMark[page];i1++)
                    in.readLine();
                for(i1=pageMark[page];i1<13854;i1++){
                    s1 = in.readLine();
                    if(s1.toLowerCase().indexOf("\""+searchterm)>=0){
                        song = new Song(s1);
                        if(song.isNameABC(searchterm)<10){
                            result.addElement(song);
                            if(result.size()>=SIZEPERPAGE){
                                pageMark[page+1] = i1;
                                next = true;
                                break;
                            }
                        }
                    }
                    if(searchterm.equals("0")){
                        int in = s1.indexOf("\"");
                        if(Character.isDigit(s1.charAt(in+1)))
//                        for(int j=0;j<10;j++)
//                            if(s1.toLowerCase().indexOf("\""+j)>=0)
                            {
                                song = new Song(s1);
                                if(song.isNameABC(searchterm)<10){
                                    result.addElement(song);
                                    if(result.size()>=SIZEPERPAGE){
                                        pageMark[page+1] = i1;
                                        next = true;
                                        break;
                                    }
                                }
                            }
                    }
                    if(i1%3000==0)System.out.println(""+i1);
                }
                inps.close();
                in.close();
                if(result.size()<=0){
                    searching.setText("Không có kết quả.");
                    repaint();
                }
                else showResult();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    
    class findAllArtists extends Thread{
        int page;
        String term;
        public findAllArtists(final String re,final int page){
            this.page = page;
            term = re.toLowerCase();
            if(page==0)for(int i=0;i<pageMark.length;i++)pageMark[i] = 0;
        }
        public void run(){
            resultArt.removeAllElements();
            next = false;
            System.out.println("Search All Artist:" + term);
            inps = getClass().getResourceAsStream("/art.txt");
            try{
                ir = new InputStreamReader(inps,"UTF-8");
                in = new BufferedReader(ir);
                String s1="";
                Artist art;
                int i1;
                System.out.println("from "+pageMark[page]);
                for(i1=0;i1<pageMark[page];i1++)
                    in.readLine();
                for(i1=pageMark[page];i1<3459;i1++){
                    s1 = in.readLine();
                    if(s1.toLowerCase().indexOf(term)>=0){
                        art = new Artist(s1);
                        resultArt.addElement(art);
                        if(resultArt.size()>=SIZEPERPAGE){
                            pageMark[page+1] = i1;
                            next = true;
                            break;
                        }
                    }
                }
                inps.close();
                in.close();
                if(resultArt.size()<=0){
                    searching.setText("Không có kết quả.");
                    repaint();
                }
                else showResult();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    
    Command com,exit;
    void addCmd(){
        try {
            com = new Command("Tùy chọn", Image.createImage("/menu.png"));
            exit = new Command("Thoát", Image.createImage("/back (2).png"));
            removeAllCommands();
            addCommand(com);
            addCommand(exit);
            Style s = new Style();
            
            s.setMargin(0,0,0,0);
            s.setPadding(0,0,0,0);
            s.setBorder(null);
            getSoftButton(0).setUnselectedStyle(s);
            getSoftButton(0).setPressedStyle(s);
            getSoftButton(0).setSelectedStyle(s);
            getSoftButton(0).setFocusable(false);
            getSoftButton(1).setUnselectedStyle(s);
            getSoftButton(1).setPressedStyle(s);
            getSoftButton(1).setSelectedStyle(s);
            getSoftButton(1).setFocusable(false);
            repaint();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
 
    protected void actionCommand(Command cmd) {
        super.actionCommand(cmd);
        if(cmd.equals(com)){
            if(m==null) m = new MenuDialog();
            m.show(60,0,0,40,true,false);
            
        }else{
            if(!abcshow)Main.getInstance().showFirst();
        }
        if(abcshow){
            abcshow = false;
            removeComponent(abc);
            try{
                if(searchType==0)addComponent(lblAbc);
            }catch(Exception e){}
            addComponent(lv);
        }
    }
    
    Button search,favunfav,favolist,help,cancel;
    MenuDialog m;
    int []favlist;
    Command back,emp;
    int contextFocus = 0;
    
    class MenuDialog extends Dialog{
        public MenuDialog() {
            setLayout(new BoxLayout(BoxLayout.Y_AXIS));
            getStyle().setAlignment(Component.CENTER);
            search = new Button("Tìm");
            favunfav = new Button("Thích/bỏ thích");
            favolist = new Button("Danh sách ưa thích");
            help = new Button("Giúp đỡ");
            cancel = new Button("Quay lại");
            S.setTrans(search);S.setTrans(favunfav);
            S.setTrans(favolist);S.setTrans(help);
            S.setTrans(cancel);
            try{
                back = new Command("Quay lại", Image.createImage("/back (2).png"));
                emp = new Command("", Image.createImage("/btnempty.png"));
            }catch(Exception e){}
            addComponent(search);
            addComponent(favunfav);
            addComponent(favolist);
            addComponent(help);
            addComponent(cancel);
            addCommand(back);
            addCommand(emp);
            Style s = new Style();
            s.setMargin(0,0,0,0);
            s.setPadding(0,0,0,0);
            s.setBorder(null);
            getSoftButton(0).setUnselectedStyle(s);
            getSoftButton(0).setPressedStyle(s);
            getSoftButton(0).setSelectedStyle(s);
            getSoftButton(0).setFocusable(false);
            getSoftButton(1).setUnselectedStyle(s);
            getSoftButton(1).setPressedStyle(s);
            getSoftButton(1).setSelectedStyle(s);
            getSoftButton(1).setFocusable(false);
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    lastSearch = txtSearch.getText();
                    if(txtSearch.getText().length()>1){
                        result = new Vector();
                        page = 0;
                        newLv();
                        searching.setText("Đang tìm...");
                        lv.addItem(searching);
                        repaint();
                        if(searchThread!=null&&searchThread.isAlive())searchThread.interrupt();
                        searchThread = new findAll(""+txtSearch.getText(),page);
                        searchThread.start();
                    }
                    m.dispose();
                }
            });
            favunfav.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    try{
                        Song s = (Song)result.elementAt(lv.getSelectedIndex());
                        if(!s.isFav()){
                            s.fav();
                            ((Label)vout.elementAt(lv.getSelectedIndex())).setIcon(fav);
                        }
                        else{
                            s.unFav();
                            ((Label)vout.elementAt(lv.getSelectedIndex())).setIcon(nofav);
                        }
                        repaint();
                    }catch(Exception e){
                    }
                    m.dispose();
                }
            });
            favolist.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    findFav();
                    m.dispose();
                }
            });
            help.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    Main.getInstance().showHelp();
                }
            });
            cancel.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    m.dispose();
                }
            });
        }
    }
    
    void findFav(){
        favlist = Song.getFavList();
        searchType = 4;
        page = 0;
        result = new Vector();
        newLv();
        searching.setText("Đang tìm...");
        lv.addItem(searching);
        repaint();
        new findAll("", 0).start();
    }
    class parsenew extends Thread{
        public parsenew(){
        }
        public void run(){
            inps = getClass().getResourceAsStream("/new.txt");
            try{
                ir = new InputStreamReader(inps,"UTF-8");
                in = new BufferedReader(ir);
                Vector vs = new Vector();
                Song s;String s1;
                int i1;
                for(i1=0;i1<307;i1++){
                    s = new Song();
                    s1 = in.readLine();
                    s.ID = Integer.parseInt(s1);
                    s1 = in.readLine();
                    s.name = s1;
                    s1 = in.readLine();
                    s.lyric = s1;
                    s1 = in.readLine();
                    s.artist = s1;
                    vs.addElement(s);
                }
                for(i1=0;i1<307;i1++){
                    s = (Song)vs.elementAt(i1);
                    s1 = in.readLine();
                    s1 = in.readLine();
                    s.rawname = s1.toLowerCase();
                    s1 = in.readLine();
                    s.rawlyric = s1.toLowerCase();
                    s1 = in.readLine();
                    s.rawartist = s1.toLowerCase();
                    s.out();
                }
                inps.close();
                in.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
}
